package com.example.demo.controller;

import cn.hutool.json.JSONObject;
import com.example.demo.entity.Medicines;
import com.example.demo.service.MedicinesService;
import com.example.demo.utils.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("services/medicines")
@RequiredArgsConstructor
@Slf4j
public class MedicinesController {
    
    private final MedicinesService medicinesService;
    
    @PostMapping("/synchronization")
    public Result addMedicines(@RequestBody JSONObject jsonObject) {
        log.info("接受的参数jsonObject：{}", jsonObject);
        Medicines medicines = new Medicines();
        medicines.setName(jsonObject.getStr("name"));
        medicines.setDescription(jsonObject.getStr("description"));
        medicines.setQuantity(jsonObject.getDouble("quantity"));
        medicines.setUnit(jsonObject.getStr("unit"));
        medicines.setSynced(jsonObject.getInt("synced"));
        medicines.setCreatedat(jsonObject.getStr("createdat"));
        return Result.success();
    }
    
}
